package com.cs.study.homework._0206;

import java.util.Arrays;
import java.util.Scanner;

public class Average {
    public static void main(String[] args) {
        System.out.println("请输入十个评委的分数：");
        Scanner sc = new Scanner(System.in);
        double[] arr = new double[10];
        for (int i = 0; i < 10; i++) {
            double score = sc.nextDouble();
            arr[i] = score;
        }
        System.out.println("评委打分分别是" + Arrays.toString(arr));
        double average = getAverage(arr);
        System.out.println("最终得分是"+average);
    }

    public static double getAverage(double[] arr) {
        double average;
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        double max = getMax(arr);
        double min = getMin(arr);
        average = (sum - max - min) / 8;
        return average;
    }

    public static double getMax(double[] arr) {
        double max = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] >= max) {
                max = arr[i];
            }
        }
        return max;
    }

    public static double getMin(double[] arr) {
        double min = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] <= min) {
                min = arr[i];
            }
        }
        return min;
    }
}
